<!DOCTYPE html>
<html lang="zh-CN,en,default">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.0.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Monda:300,300italic,400,400italic,700,700italic|Lobster Two:300,300italic,400,400italic,700,700italic|Amita:300,300italic,400,400italic,700,700italic|Montserrat:300,300italic,400,400italic,700,700italic|PT Mono:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"dpbirder.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"flat"},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":true,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":true,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

<script>
    (function(d, w, c) {
        w.ChatraID = 'Z8KH5JTPhxGC84tKb';
        var s = d.createElement('script');
        w[c] = w[c] || function() {
            (w[c].q = w[c].q || []).push(arguments);
        };
        s.async = true;
        s.src = 'https://call.chatra.io/chatra.js';
        if (d.head) d.head.appendChild(s);
    })(document, window, 'Chatra');
</script>
  <meta name="description" content="1、介绍 该文档是记录学习黑马小程序开发课程后对于课程的一些补充、总结、所遇到的问题以及一些问题的解决。文档主要包括小程序基础部分以及项目实践——黑马优购项目。">
<meta property="og:type" content="article">
<meta property="og:title" content="小程序学习总结">
<meta property="og:url" content="http://dpbirder.gitee.io/2021/11/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/index.html">
<meta property="og:site_name" content="dpBirder&#39;s Blog">
<meta property="og:description" content="1、介绍 该文档是记录学习黑马小程序开发课程后对于课程的一些补充、总结、所遇到的问题以及一些问题的解决。文档主要包括小程序基础部分以及项目实践——黑马优购项目。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114112638871.png">
<meta property="og:image" content="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114112715076.png">
<meta property="og:image" content="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143024225.png">
<meta property="og:image" content="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143156411.png">
<meta property="og:image" content="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114112855878.png">
<meta property="og:image" content="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143427018.png">
<meta property="og:image" content="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143403185.png">
<meta property="og:image" content="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143233048.png">
<meta property="og:image" content="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143535670.png">
<meta property="og:image" content="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143934785.png">
<meta property="og:image" content="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143605553.png">
<meta property="og:image" content="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114142809887.png">
<meta property="og:image" content="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143833058.png">
<meta property="article:published_time" content="2021-11-13T08:48:51.000Z">
<meta property="article:modified_time" content="2022-11-22T14:48:21.794Z">
<meta property="article:author" content="dpbirder">
<meta property="article:tag" content="小程序">
<meta property="article:tag" content="项目">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114112638871.png">

<link rel="canonical" href="http://dpbirder.gitee.io/2021/11/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>
<script> 
 (function(){
        if(''){
            if (prompt('请输入文章密码') !== ''){
                alert('密码错误！');
                history.back();
            }
        }
    })();
</script>
  <title>小程序学习总结 | dpBirder's Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">dpBirder's Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">15</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">26</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">51</span></a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

  <a href="https://github.com/zhengzp2019" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://dpbirder.gitee.io/2021/11/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/boy.jpg">
      <meta itemprop="name" content="dpbirder">
      <meta itemprop="description" content="目前研一就读于西安电子科技大学">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="dpBirder's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          小程序学习总结
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-11-13 16:48:51" itemprop="dateCreated datePublished" datetime="2021-11-13T16:48:51+08:00">2021-11-13</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-11-22 22:48:21" itemprop="dateModified" datetime="2022-11-22T22:48:21+08:00">2022-11-22</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E8%B7%B5/" itemprop="url" rel="index"><span itemprop="name">项目实践</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E8%B7%B5/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">小程序开发</span></a>
                </span>
            </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>7.4k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>7 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="1-介绍"><a class="markdownIt-Anchor" href="#1-介绍"></a> 1、介绍</h2>
<p>该文档是记录学习<a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1nE41117BQ">黑马小程序开发</a>课程后对于课程的一些补充、总结、所遇到的问题以及一些问题的解决。文档主要包括小程序基础部分以及项目实践——黑马优购项目。</p>
<a id="more"></a>
<h2 id="2-基础部分"><a class="markdownIt-Anchor" href="#2-基础部分"></a> 2、基础部分</h2>
<p><a target="_blank" rel="noopener" href="https://github.com/zhengzp2019/heimayougou/blob/master/%E6%80%9D%E7%BB%B4%E5%AF%BC%E5%9B%BE.xmind">思维导图</a>，这里只罗列需要了解的知识点，具体内容可观看<a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1nE41117BQ">视频课程</a>，查阅小程序<a target="_blank" rel="noopener" href="https://developers.weixin.qq.com/miniprogram/dev/framework/">官方文档</a>或者<a target="_blank" rel="noopener" href="https://github.com/zhengzp2019/heimayougou/blob/master/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F-%E5%9F%BA%E7%A1%80.pdf">黑马文档</a>。</p>
<h2 id="3-项目实践"><a class="markdownIt-Anchor" href="#3-项目实践"></a> 3、项目实践</h2>
<h3 id="1-首页"><a class="markdownIt-Anchor" href="#1-首页"></a> 1、 首页</h3>
<img src="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114112638871.png" alt="image-20211114112638871" style="zoom:50%;">
<ol>
<li>
<p>数据请求：微信提供的api为<code>wx.request</code>，使用之前将其封装为promise方式，并使用ES7中async方法发出异步请求。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> ajaxTimes = <span class="number">0</span>;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * Promise 形式的Request</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">&#123;Object&#125;</span> </span>params </span></span><br><span class="line"><span class="comment"> * <span class="doctag">@returns <span class="variable">res</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> request = <span class="function">(<span class="params">params</span>) =&gt;</span> &#123;</span><br><span class="line">    ajaxTimes++;</span><br><span class="line">    <span class="comment">// 显示加载中效果</span></span><br><span class="line">    wx.showLoading(&#123;</span><br><span class="line">        title: <span class="string">&quot;加载中&quot;</span>,</span><br><span class="line">        mask: <span class="literal">true</span>,</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 定义公共URL</span></span><br><span class="line">    <span class="keyword">const</span> baseUrl = <span class="string">&quot;https://api-hmugo-web.itheima.net/api/public/v1&quot;</span>;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</span><br><span class="line">        wx.request(&#123;</span><br><span class="line">            ...params,</span><br><span class="line">            header: header,</span><br><span class="line">            url: baseUrl + params.url,</span><br><span class="line">            success: <span class="function">(<span class="params">result</span>) =&gt;</span> &#123;</span><br><span class="line">                resolve(result.data.message);<span class="comment">// 简化接口数据</span></span><br><span class="line">            &#125;,</span><br><span class="line">            fail: <span class="function">(<span class="params">err</span>) =&gt;</span> &#123;</span><br><span class="line">                reject(err);</span><br><span class="line">            &#125;,</span><br><span class="line">            complete: <span class="function">() =&gt;</span> &#123;</span><br><span class="line">                ajaxTimes--;</span><br><span class="line">                <span class="keyword">if</span> (ajaxTimes === <span class="number">0</span>) &#123;<span class="comment">// 关闭正在等待的图标</span></span><br><span class="line">                    wx.hideLoading();</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li>
<p>这里的空间都是<code>navigator</code>，分类页面需要跳转到tabber上，故需要注意修改<code>open-type</code>内容</p>
</li>
</ol>
<h3 id="问题及解决"><a class="markdownIt-Anchor" href="#问题及解决"></a> 问题及解决</h3>
<p>这里的跳转连接是从后台请求的，而后台请求的链接有点乱，不符合开始建立的页面逻辑，所以我把这里的跳转链接基本都是写死的。</p>
<h3 id="2-分类页面"><a class="markdownIt-Anchor" href="#2-分类页面"></a> 2、分类页面</h3>
<img src="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114112715076.png" alt="image-20211114112715076" style="zoom:50%;">
<ol>
<li>
<p>查看官方文档学习<code>scroll-view</code>的使用方式</p>
</li>
<li>
<p>使用点击事件使得点击左侧内容，右侧可以做出相应</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">view</span></span></span><br><span class="line"><span class="tag">  <span class="attr">class</span>=<span class="string">&quot;menu_item &#123;&#123;index===currentIndex?&#x27;active&#x27;:&#x27;&#x27;&#125;&#125;&quot;</span></span></span><br><span class="line"><span class="tag">  <span class="attr">wx:for</span>=<span class="string">&quot;&#123;&#123;leftMenuList&#125;&#125;&quot;</span></span></span><br><span class="line"><span class="tag">  <span class="attr">wx:key</span>=<span class="string">&quot;*this&quot;</span></span></span><br><span class="line"><span class="tag">  <span class="attr">bindtap</span>=<span class="string">&quot;handleItemTap&quot;</span></span></span><br><span class="line"><span class="tag">  <span class="attr">data-index</span>=<span class="string">&quot;&#123;&#123;index&#125;&#125;&quot;</span></span></span><br><span class="line"><span class="tag">&gt;</span></span><br><span class="line">  &#123;&#123;item&#125;&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 处理左侧点击事件</span></span><br><span class="line">handleItemTap(e) &#123;</span><br><span class="line">  <span class="comment">// console.log(e);</span></span><br><span class="line">  <span class="keyword">const</span> &#123; index &#125; = e.currentTarget.dataset;</span><br><span class="line">  <span class="comment">// 构造右侧的商品数据</span></span><br><span class="line">  <span class="keyword">let</span> rightContent = <span class="built_in">this</span>.Cates[index].children;</span><br><span class="line">   </span><br><span class="line">  <span class="built_in">this</span>.setData(&#123;</span><br><span class="line">    currentIndex: index,</span><br><span class="line">    rightContent</span><br><span class="line">  &#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li>
<p>less语言编译为wxss语法</p>
<figure class="highlight less"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 使用&#x27;~&#x27;和字符串的形式实现wxss原样编译</span></span><br><span class="line"><span class="comment">// 参考链接：https://less.bootcss.com/#%E8%BD%AC%E4%B9%89%EF%BC%88escaping%EF%BC%89</span></span><br><span class="line"><span class="attribute">height</span>: <span class="string">~&#x27;calc(100vh - 90rpx)&#x27;</span>;</span><br></pre></td></tr></table></figure>
</li>
<li>
<p>向缓存中存/取数据</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 存数据</span></span><br><span class="line">wx.setStorageSync(<span class="string">&quot;key&quot;</span>,data);</span><br><span class="line"><span class="comment">// 取数据</span></span><br><span class="line">wx.getStorageSync(<span class="string">&quot;key&quot;</span>);</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h3 id="3-商品列表"><a class="markdownIt-Anchor" href="#3-商品列表"></a> 3、商品列表</h3>
<img src="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143024225.png" alt="image-20211114112855878" style="zoom:50%;">
<ol>
<li>两行显示布局</li>
</ol>
<figure class="highlight less"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 显示...效果</span></span><br><span class="line"><span class="attribute">display</span>: -webkit-box;</span><br><span class="line"><span class="attribute">overflow</span>: hidden;</span><br><span class="line"><span class="attribute">-webkit-box-orient</span>: vertical;</span><br><span class="line"><span class="attribute">-webkit-line-clamp</span>: <span class="number">2</span>;</span><br></pre></td></tr></table></figure>
<h3 id="4-商品详情"><a class="markdownIt-Anchor" href="#4-商品详情"></a> 4、商品详情</h3>
<img src="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143156411.png" alt="image-20211114142809887" style="zoom:50%;">
<ol>
<li>底部工具栏布局：需要使用css中定位的知识，将该组件定义在页面底部，为了使点击底部图标能够执行功能，这里将button以透明的方式显示在view组件的上面</li>
<li>分享与联系客服功能需要分别修改button按钮的<code>open-type</code>属性</li>
</ol>
<h3 id="5-购物车"><a class="markdownIt-Anchor" href="#5-购物车"></a> 5、购物车</h3>
<img src="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114112855878.png" alt="image-20211114143024225" style="zoom:50%;">
<img src="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143427018.png" alt="image-20211114143156411" style="zoom:50%;">
<ol>
<li>获取收获地址按钮在获取地址成功后需要显示地址，需要使用条件渲染页面</li>
<li>该页面的逻辑功能实现较为复杂</li>
</ol>
<h3 id="6-支付"><a class="markdownIt-Anchor" href="#6-支付"></a> 6、支付</h3>
<img src="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143403185.png" alt="image-20211114143233048" style="zoom:50%;">
<ol>
<li>
<p>该功能需要企业账号才能实现，这里的token并不是从小程序后台请求的仅仅使用一个测试token，测试该页面逻辑</p>
<p><code>BearereyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo</code></p>
</li>
</ol>
<h3 id="7-个人中心"><a class="markdownIt-Anchor" href="#7-个人中心"></a> 7、个人中心</h3>
<img src="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143233048.png" alt="image-20211114143403185" style="zoom:50%;">
<ol>
<li>
<p>这里需要获取用户个人信息，视频中使用的方法现以不维护，这里使用的是<code>wx.getUserProfile</code>方法</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * promise 形式  getUserProfile</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">&#123;Object&#125;</span> </span>param0 参数</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@returns </span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> getUserProfile = <span class="function">(<span class="params">&#123; desc &#125;</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</span><br><span class="line">        wx.getUserProfile(&#123;</span><br><span class="line">            desc: desc, <span class="comment">// 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写</span></span><br><span class="line">            success: <span class="function">(<span class="params">res</span>) =&gt;</span> &#123;</span><br><span class="line">                resolve(res);</span><br><span class="line">            &#125;,</span><br><span class="line">            fail: <span class="function">(<span class="params">err</span>) =&gt;</span> &#123;</span><br><span class="line">                reject(err);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li>
<p>图像模糊效果需要用到CSS3的滤镜方法</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">filter</span>: <span class="selector-tag">blur</span>(10<span class="selector-tag">rpx</span>);</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h3 id="8-授权"><a class="markdownIt-Anchor" href="#8-授权"></a> 8、授权</h3>
<img src="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143535670.png" alt="image-20211114143427018" style="zoom:50%;">
<ol>
<li>授权功能与获取用户个人信息功能相同</li>
</ol>
<h3 id="9-订单查询"><a class="markdownIt-Anchor" href="#9-订单查询"></a> 9、订单查询</h3>
<img src="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143934785.png" alt="image-20211114143535670" style="zoom:50%;">
<h3 id="10-商品收藏"><a class="markdownIt-Anchor" href="#10-商品收藏"></a> 10、商品收藏</h3>
<img src="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143605553.png" alt="image-20211114143605553" style="zoom:50%;">
<h3 id="11-搜索"><a class="markdownIt-Anchor" href="#11-搜索"></a> 11、搜索</h3>
<img src="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114142809887.png" alt="image-20211114143833058" style="zoom:50%;">
<ol>
<li>
<p>为了防止程序多次请求在搜索框中添加防抖功能</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 防抖 功能</span></span><br><span class="line"><span class="built_in">clearTimeout</span>(<span class="built_in">this</span>.TimeId);</span><br><span class="line"><span class="built_in">this</span>.TimeId = <span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="built_in">this</span>.qSearch(value);</span><br><span class="line">&#125;, <span class="number">1000</span>);</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h3 id="12-意见反馈"><a class="markdownIt-Anchor" href="#12-意见反馈"></a> 12、意见反馈</h3>
<img src="https://raw.githubusercontent.com/zhengzp2019/Image/main/image-20211114143833058.png" alt="image-20211114143934785" style="zoom:50%;">
<h2 id="4-附录"><a class="markdownIt-Anchor" href="#4-附录"></a> 4、附录</h2>
<h3 id="1-工具"><a class="markdownIt-Anchor" href="#1-工具"></a> 1、工具</h3>
<ul>
<li>
<p><a target="_blank" rel="noopener" href="https://code.visualstudio.com/">vscode</a>及其开发插件</p>
<ul>
<li>
<p>easy less</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&quot;less.compile&quot;: &#123;</span><br><span class="line">  &quot;outExt&quot;: &quot;.wxss&quot;,</span><br><span class="line">  &quot;sourceMap&quot;: false</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>
</li>
<li>
<p>wechat-snippet</p>
</li>
<li>
<p>小程序开发助手</p>
</li>
<li>
<p>CSS Tree</p>
</li>
<li>
<p>wxapp-helper</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&quot;wxapp-helper.namingConvention&quot;: &quot;camelcase&quot;,</span><br><span class="line">&quot;wxapp-helper.component.typescript&quot;: false,</span><br><span class="line">&quot;wxapp-helper.component.name&quot;: &quot;&quot;,</span><br><span class="line">&quot;wxapp-helper.component.json&quot;: &quot;&#123;\n  \&quot;component\&quot;: true\n&#125;&quot;,</span><br><span class="line">&quot;wxapp-helper.component.wxml&quot;: &quot;&quot;,</span><br><span class="line">&quot;wxapp-helper.component.script&quot;: &quot;base64:Q29tcG9uZW50KHsKICBkYXRhOiB7fSwKICBwcm9wZXJ0aWVzOiB7fSwKICBtZXRob2RzOiB7fSwKICBvcHRpb25zOiB7CiAgICBhZGRHbG9iYWxDbGFzczogdHJ1ZQogIH0KfSk=&quot;,</span><br><span class="line">&quot;wxapp-helper.component.wxss&quot;: &quot;&quot;,</span><br></pre></td></tr></table></figure>
</li>
<li>
<p>WXML-Language Services</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">&quot;minapp-vscode.disableAutoConfig&quot;: true,</span><br><span class="line">&quot;minapp-vscode.wxmlFormatter&quot;: &quot;prettier&quot;, //指定格式化工具</span><br><span class="line">&quot;minapp-vscode.prettyHtml&quot;: &#123;</span><br><span class="line">  <span class="comment">// prettyHtml 默认配置</span></span><br><span class="line">  &quot;useTabs&quot;: false,</span><br><span class="line">  &quot;tabWidth&quot;: 2,</span><br><span class="line">  &quot;printWidth&quot;: 100,</span><br><span class="line">  &quot;singleQuote&quot;: false,</span><br><span class="line">  &quot;usePrettier&quot;: true,</span><br><span class="line">  &quot;wrapAttributes&quot;: true,</span><br><span class="line">  &quot;sortAttributes&quot;: true</span><br><span class="line">&#125;,</span><br><span class="line">&quot;minapp-vscode.prettier&quot;: &#123;</span><br><span class="line">  <span class="comment">//prettier 更多参考https://prettier.io/docs/en/options.html</span></span><br><span class="line">  &quot;useTabs&quot;: false,</span><br><span class="line">  &quot;tabWidth&quot;: 2,</span><br><span class="line">  &quot;printWidth&quot;: 100,</span><br><span class="line">  &quot;singleQuote&quot;: false</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li>
<p><a target="_blank" rel="noopener" href="https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html">微信开发者工具</a></p>
</li>
<li>
<p><a target="_blank" rel="noopener" href="https://www.snipaste.com/">Snipaste</a>(截图工具)</p>
</li>
</ul>
<h3 id="2-参考文档"><a class="markdownIt-Anchor" href="#2-参考文档"></a> 2、参考文档</h3>
<ul>
<li><a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/">MDN</a></li>
<li><a target="_blank" rel="noopener" href="https://developers.weixin.qq.com/miniprogram/dev/framework/">微信小程序开发文档</a></li>
<li><a target="_blank" rel="noopener" href="https://github.com/zhengzp2019/heimayougou/blob/master/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F-%E5%9F%BA%E7%A1%80.pdf">黑马课程文档</a></li>
</ul>
<h3 id="3-代码中用到的全部promise封装"><a class="markdownIt-Anchor" href="#3-代码中用到的全部promise封装"></a> 3、代码中用到的全部Promise封装</h3>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * promise 形式  chooseAddress</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> chooseAddress = <span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</span><br><span class="line">        wx.chooseAddress(&#123;</span><br><span class="line">            success: <span class="function">(<span class="params">result</span>) =&gt;</span> &#123;</span><br><span class="line">                resolve(result);</span><br><span class="line">            &#125;,</span><br><span class="line">            fail: <span class="function">(<span class="params">err</span>) =&gt;</span> &#123;</span><br><span class="line">                reject(err);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * promise 形式  showModal</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">&#123;Object&#125;</span> </span>param0 参数</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@returns </span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> showModal = <span class="function">(<span class="params">&#123; content &#125;</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</span><br><span class="line">        wx.showModal(&#123;</span><br><span class="line">            title: <span class="string">&#x27;提示&#x27;</span>,</span><br><span class="line">            content: content,</span><br><span class="line">            success: <span class="function">(<span class="params">res</span>) =&gt;</span> &#123;</span><br><span class="line">                resolve(res);</span><br><span class="line">            &#125;,</span><br><span class="line">            fail: <span class="function">(<span class="params">err</span>) =&gt;</span> &#123;</span><br><span class="line">                reject(err);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * promise 形式  showToast</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">&#123;Object&#125;</span> </span>param0 参数</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@returns </span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> showToast = <span class="function">(<span class="params">&#123; title &#125;</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</span><br><span class="line">        wx.showToast(&#123;</span><br><span class="line">            title: title,</span><br><span class="line">            icon: <span class="string">&#x27;none&#x27;</span>,</span><br><span class="line">            mask: <span class="literal">true</span>,</span><br><span class="line">            success: <span class="function">(<span class="params">res</span>) =&gt;</span> &#123;</span><br><span class="line">                resolve(res);</span><br><span class="line">            &#125;,</span><br><span class="line">            fail: <span class="function">(<span class="params">err</span>) =&gt;</span> &#123;</span><br><span class="line">                reject(err);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * promise 形式  getUserProfile</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">&#123;Object&#125;</span> </span>param0 参数</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@returns </span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> getUserProfile = <span class="function">(<span class="params">&#123; desc &#125;</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</span><br><span class="line">        wx.getUserProfile(&#123;</span><br><span class="line">            desc: desc, <span class="comment">// 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写</span></span><br><span class="line">            success: <span class="function">(<span class="params">res</span>) =&gt;</span> &#123;</span><br><span class="line">                resolve(res);</span><br><span class="line">            &#125;,</span><br><span class="line">            fail: <span class="function">(<span class="params">err</span>) =&gt;</span> &#123;</span><br><span class="line">                reject(err);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * promise 形式  login</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@returns </span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> login = <span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</span><br><span class="line">        wx.login(&#123;</span><br><span class="line">            timeout: <span class="number">10000</span>,</span><br><span class="line">            success: <span class="function">(<span class="params">result</span>) =&gt;</span> &#123;</span><br><span class="line">                resolve(result);</span><br><span class="line">            &#125;,</span><br><span class="line">            fail: <span class="function">(<span class="params">err</span>) =&gt;</span> &#123;</span><br><span class="line">                reject(err);</span><br><span class="line">            &#125;,</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * promise 形式 requestPayment</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">&#123;Object&#125;</span> </span>pay 小程序的微信支付</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@returns </span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> requestPayment = <span class="function">(<span class="params">pay</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</span><br><span class="line">        wx.requestPayment(&#123;</span><br><span class="line">            ...pay,</span><br><span class="line">            success: <span class="function">(<span class="params">result</span>) =&gt;</span> &#123;</span><br><span class="line">                resolve(result);</span><br><span class="line">            &#125;,</span><br><span class="line">            fail: <span class="function">(<span class="params">err</span>) =&gt;</span> &#123; reject(err); &#125;</span><br><span class="line">        &#125;);</span><br><span class="line"></span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">let</span> ajaxTimes = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * Promise 形式的Request</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">&#123;Object&#125;</span> </span>params </span></span><br><span class="line"><span class="comment"> * <span class="doctag">@returns <span class="variable">res</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> request = <span class="function">(<span class="params">params</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="comment">// 判断url中是否带有 /my/请求的私有的路径 带上header token</span></span><br><span class="line">    <span class="keyword">let</span> header = &#123; ...params.header &#125;;</span><br><span class="line">    <span class="keyword">if</span> (params.url.includes(<span class="string">&quot;/my/&quot;</span>)) &#123;</span><br><span class="line">        <span class="comment">// 拼接header 带上token</span></span><br><span class="line">        header[<span class="string">&quot;Authorization&quot;</span>] = wx.getStorageSync(<span class="string">&quot;token&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    ajaxTimes++;</span><br><span class="line">    <span class="comment">// 显示加载中效果</span></span><br><span class="line">    wx.showLoading(&#123;</span><br><span class="line">        title: <span class="string">&quot;加载中&quot;</span>,</span><br><span class="line">        mask: <span class="literal">true</span>,</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 定义公共URL</span></span><br><span class="line">    <span class="keyword">const</span> baseUrl = <span class="string">&quot;https://api-hmugo-web.itheima.net/api/public/v1&quot;</span>;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</span><br><span class="line">        wx.request(&#123;</span><br><span class="line">            ...params,</span><br><span class="line">            header: header,</span><br><span class="line">            url: baseUrl + params.url,</span><br><span class="line">            success: <span class="function">(<span class="params">result</span>) =&gt;</span> &#123;</span><br><span class="line">                resolve(result.data.message);<span class="comment">// 简化接口数据</span></span><br><span class="line">            &#125;,</span><br><span class="line">            fail: <span class="function">(<span class="params">err</span>) =&gt;</span> &#123;</span><br><span class="line">                reject(err);</span><br><span class="line">            &#125;,</span><br><span class="line">            complete: <span class="function">() =&gt;</span> &#123;</span><br><span class="line">                ajaxTimes--;</span><br><span class="line">                <span class="keyword">if</span> (ajaxTimes === <span class="number">0</span>) &#123;<span class="comment">// 关闭正在等待的图标</span></span><br><span class="line">                    wx.hideLoading();</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

    </div>

    
    
    <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/%E5%B0%8F%E7%A8%8B%E5%BA%8F/" rel="tag"># 小程序</a>
              <a href="/tags/%E9%A1%B9%E7%9B%AE/" rel="tag"># 项目</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/07/25/%E6%90%9C%E7%B4%A2/" rel="prev" title="搜索">
      <i class="fa fa-chevron-left"></i> 搜索
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/11/14/%E8%A7%A3%E5%86%B3Github%EF%BC%9ASupport-for-password-authentication-was-removed-Please-use-a-personal-access-token-instead/" rel="next" title="解决Github：Support for password authentication was removed. Please use a personal access token instead">
      解决Github：Support for password authentication was removed. Please use a personal access token instead <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%BB%8B%E7%BB%8D"><span class="nav-text"> 1、介绍</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%9F%BA%E7%A1%80%E9%83%A8%E5%88%86"><span class="nav-text"> 2、基础部分</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E9%A1%B9%E7%9B%AE%E5%AE%9E%E8%B7%B5"><span class="nav-text"> 3、项目实践</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-%E9%A6%96%E9%A1%B5"><span class="nav-text"> 1、 首页</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%97%AE%E9%A2%98%E5%8F%8A%E8%A7%A3%E5%86%B3"><span class="nav-text"> 问题及解决</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-%E5%88%86%E7%B1%BB%E9%A1%B5%E9%9D%A2"><span class="nav-text"> 2、分类页面</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-%E5%95%86%E5%93%81%E5%88%97%E8%A1%A8"><span class="nav-text"> 3、商品列表</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-%E5%95%86%E5%93%81%E8%AF%A6%E6%83%85"><span class="nav-text"> 4、商品详情</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-%E8%B4%AD%E7%89%A9%E8%BD%A6"><span class="nav-text"> 5、购物车</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-%E6%94%AF%E4%BB%98"><span class="nav-text"> 6、支付</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-%E4%B8%AA%E4%BA%BA%E4%B8%AD%E5%BF%83"><span class="nav-text"> 7、个人中心</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-%E6%8E%88%E6%9D%83"><span class="nav-text"> 8、授权</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-%E8%AE%A2%E5%8D%95%E6%9F%A5%E8%AF%A2"><span class="nav-text"> 9、订单查询</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#10-%E5%95%86%E5%93%81%E6%94%B6%E8%97%8F"><span class="nav-text"> 10、商品收藏</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#11-%E6%90%9C%E7%B4%A2"><span class="nav-text"> 11、搜索</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12-%E6%84%8F%E8%A7%81%E5%8F%8D%E9%A6%88"><span class="nav-text"> 12、意见反馈</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E9%99%84%E5%BD%95"><span class="nav-text"> 4、附录</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-%E5%B7%A5%E5%85%B7"><span class="nav-text"> 1、工具</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-%E5%8F%82%E8%80%83%E6%96%87%E6%A1%A3"><span class="nav-text"> 2、参考文档</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-%E4%BB%A3%E7%A0%81%E4%B8%AD%E7%94%A8%E5%88%B0%E7%9A%84%E5%85%A8%E9%83%A8promise%E5%B0%81%E8%A3%85"><span class="nav-text"> 3、代码中用到的全部Promise封装</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="dpbirder"
      src="/images/boy.jpg">
  <p class="site-author-name" itemprop="name">dpbirder</p>
  <div class="site-description" itemprop="description">目前研一就读于西安电子科技大学</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">51</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">26</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">15</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="sidebar-button motion-element">
    <a onclick="Chatra('openChat', true);"><i class="fa fa-comment"></i>
    Chat
  </a>
  </div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/zhengzp2019" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;zhengzp2019" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://mail.qq.com/" title="E-Mail → https:&#x2F;&#x2F;mail.qq.com&#x2F;" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        
  <div class="languages">
    <label class="lang-select-label">
      <i class="fa fa-language"></i>
      <span>简体中文</span>
      <i class="fa fa-angle-up" aria-hidden="true"></i>
    </label>
    <select class="lang-select" data-canonical="">
      
        <option value="zh-CN" data-href="/2021/11/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/" selected="">
          简体中文
        </option>
      
        <option value="en" data-href="/en/2021/11/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/" selected="">
          English
        </option>
      
    </select>
  </div>

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">dpbirder</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">225k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">3:25</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>

<script src="/js/bookmark.js"></script>


  <script defer src="/lib/three/three.min.js"></script>
    <script defer src="/lib/three/three-waves.min.js"></script>


  
  <script>
    (function(){
      var canonicalURL, curProtocol;
      //Get the <link> tag
      var x=document.getElementsByTagName("link");
		//Find the last canonical URL
		if(x.length > 0){
			for (i=0;i<x.length;i++){
				if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
					canonicalURL=x[i].href;
				}
			}
		}
    //Get protocol
	    if (!canonicalURL){
	    	curProtocol = window.location.protocol.split(':')[0];
	    }
	    else{
	    	curProtocol = canonicalURL.split(':')[0];
	    }
      //Get current URL if the canonical URL does not exist
	    if (!canonicalURL) canonicalURL = window.location.href;
	    //Assign script content. Replace current URL with the canonical URL
      !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();
  </script>




  
<script src="/js/local-search.js"></script>




  <script>
    (function(d, w, c) {
      w.ChatraID = 'Z8KH5JTPhxGC84tKb';
      var s = d.createElement('script');
      w[c] = w[c] || function() {
        (w[c].q = w[c].q || []).push(arguments);
      };
      s.async = true;
      s.src = 'https://call.chatra.io/chatra.js';
      if (d.head) d.head.appendChild(s);
    })(document, window, 'Chatra');
  </script>









  

  

  

</body>
</html>
<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>
